﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TotalSystems.DataAccess;
using TotalSystems.Business.Public;

namespace TotalSystems.Business.Store
{
   public class CargoPaperRepository
    {
        TSContext _context = new TSContext();
        FinancialYearRepository financialYearRepository = new Public.FinancialYearRepository();

        #region Select
        public IEnumerable<STR_CargoPaper> GetCargoPaper()
        {
            return _context.STR_CargoPaper;
        }

        #endregion

        #region Insert

        public void InsertCargoPaper(STR_CargoPaper sTR_CargoPaper)
        {
            //sTR_CargoPaper.ACC_Fy_ID_fk = financialYearRepository.GetACC_FinancialYearActive().Select(x => x.ACC_Fy_ID_fk).First();
            _context.AddToSTR_CargoPaper(sTR_CargoPaper);
            _context.SaveChanges();
        }

        #endregion

        #region Update

        public void UpdateCargoPaper(STR_CargoPaper sTR_CargoPaper)
        {
            var q = _context.STR_CargoPaper.FirstOrDefault(x => x.STR_CargoPaper_ID == sTR_CargoPaper.STR_CargoPaper_ID);
            _context.STR_CargoPaper.ApplyCurrentValues(q);
            _context.SaveChanges();
        }

        #endregion
    }
}
